package commonfunc

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

type ReqMessage struct {
	Code int
	Status string
	Message interface{}
}

func ReqSuccess(c *gin.Context, message interface{})  {
	c.JSONP(http.StatusOK,ReqMessage{
		Code:http.StatusOK,
		Status:http.StatusText(http.StatusOK),
		Message:message,
	})
}

func ReqUnauthorized(c *gin.Context, message interface{})  {
	c.JSONP(http.StatusUnauthorized,ReqMessage{
		Code:http.StatusUnauthorized,
		Status:http.StatusText(http.StatusUnauthorized),
		Message:message,
	})
}

func ReqFail(c *gin.Context, message interface{})  {
	c.JSONP(http.StatusInternalServerError,ReqMessage{
		Code:http.StatusInternalServerError,
		Status:http.StatusText(http.StatusInternalServerError),
		Message:message,
	})
}

func ReqNotFound(c *gin.Context, message interface{})  {
	c.JSONP(http.StatusNotFound,ReqMessage{
		Code:http.StatusNotFound,
		Status:http.StatusText(http.StatusNotFound),
		Message:message,
	})
}

func ReqMissParams(c *gin.Context, message interface{})  {
	c.JSONP(http.StatusBadRequest,ReqMessage{
		Code:http.StatusBadRequest,
		Status:http.StatusText(http.StatusBadRequest),
		Message:fmt.Sprintf("Miss Params: %#v\n",message),
	})
}


